{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/javascript": [
       "IPython.notebook.set_autosave_interval(60000)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Autosaving every 60 seconds\n"
     ]
    }
   ],
   "source": [
    "%autosave 60"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "BUCKET_NAME = \"msil_raw\"\n",
    "FOLDER_NAME = \"training_data\"\n",
    "TRAINFILE = \"trainset.csv\"\n",
    "VALIDFILE = \"validset.csv\"\n",
    "TESTFILE = \"testset.csv\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "import google.datalab.storage as storage\n",
    "import pandas as pd\n",
    "from io import BytesIO\n",
    "\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "import xgboost as xgb\n",
    "from sklearn.model_selection import GridSearchCV\n",
    "import time\n",
    "from datetime import datetime\n",
    "from scipy import integrate"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# setting up the parameters\n",
    "plt.rcParams[\"figure.figsize\"] = (10, 10)\n",
    "pd.set_option(\"display.max_rows\", 200)\n",
    "pd.set_option(\"display.max_columns\", 200)\n",
    "pd.set_option(\"precision\", 15)\n",
    "sns.set_style(\"darkgrid\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>IMEI</th>\n",
       "      <th>Year</th>\n",
       "      <th>Month</th>\n",
       "      <th>Day</th>\n",
       "      <th>Hour</th>\n",
       "      <th>Minute</th>\n",
       "      <th>Seconds</th>\n",
       "      <th>tp</th>\n",
       "      <th>sp</th>\n",
       "      <th>EVVSP</th>\n",
       "      <th>EVVSP_delta</th>\n",
       "      <th>EVVSP_change</th>\n",
       "      <th>EVGPO</th>\n",
       "      <th>EVOAS</th>\n",
       "      <th>EVIGM_Latest</th>\n",
       "      <th>EVCOM_Latest</th>\n",
       "      <th>EVACO_Z</th>\n",
       "      <th>EVIRT_Min</th>\n",
       "      <th>EVDI2</th>\n",
       "      <th>EVBMI_Latest</th>\n",
       "      <th>EVBMA_Latest</th>\n",
       "      <th>EVVAC</th>\n",
       "      <th>EVVAC_delta</th>\n",
       "      <th>EVVAC_change</th>\n",
       "      <th>EVODO</th>\n",
       "      <th>EVODOH</th>\n",
       "      <th>EVSMA_EWMA</th>\n",
       "      <th>EVSMA_delta</th>\n",
       "      <th>EVSMA_in</th>\n",
       "      <th>combine</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>7</td>\n",
       "      <td>2018</td>\n",
       "      <td>11</td>\n",
       "      <td>15</td>\n",
       "      <td>10</td>\n",
       "      <td>58</td>\n",
       "      <td>49</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>26.0</td>\n",
       "      <td>-51</td>\n",
       "      <td>-51</td>\n",
       "      <td>-1008.0</td>\n",
       "      <td>-41</td>\n",
       "      <td>20</td>\n",
       "      <td>21.5</td>\n",
       "      <td>21.5</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>690</td>\n",
       "      <td>0.0</td>\n",
       "      <td>93.200000000000003</td>\n",
       "      <td>0.0</td>\n",
       "      <td>93.200000000000003</td>\n",
       "      <td>1606</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>7</td>\n",
       "      <td>2018</td>\n",
       "      <td>11</td>\n",
       "      <td>15</td>\n",
       "      <td>10</td>\n",
       "      <td>58</td>\n",
       "      <td>50</td>\n",
       "      <td>1</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>26.0</td>\n",
       "      <td>-51</td>\n",
       "      <td>-51</td>\n",
       "      <td>-1004.0</td>\n",
       "      <td>-41</td>\n",
       "      <td>20</td>\n",
       "      <td>21.5</td>\n",
       "      <td>21.5</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>690</td>\n",
       "      <td>0.0</td>\n",
       "      <td>93.200000000000003</td>\n",
       "      <td>0.0</td>\n",
       "      <td>93.200000000000003</td>\n",
       "      <td>1606</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>7</td>\n",
       "      <td>2018</td>\n",
       "      <td>11</td>\n",
       "      <td>15</td>\n",
       "      <td>10</td>\n",
       "      <td>58</td>\n",
       "      <td>51</td>\n",
       "      <td>1</td>\n",
       "      <td>2000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>26.0</td>\n",
       "      <td>-51</td>\n",
       "      <td>-51</td>\n",
       "      <td>-1016.0</td>\n",
       "      <td>-41</td>\n",
       "      <td>20</td>\n",
       "      <td>21.5</td>\n",
       "      <td>21.5</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>690</td>\n",
       "      <td>0.0</td>\n",
       "      <td>93.200000000000003</td>\n",
       "      <td>0.0</td>\n",
       "      <td>93.200000000000003</td>\n",
       "      <td>1606</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>7</td>\n",
       "      <td>2018</td>\n",
       "      <td>11</td>\n",
       "      <td>15</td>\n",
       "      <td>10</td>\n",
       "      <td>58</td>\n",
       "      <td>52</td>\n",
       "      <td>1</td>\n",
       "      <td>3000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>26.0</td>\n",
       "      <td>-51</td>\n",
       "      <td>-51</td>\n",
       "      <td>-1002.0</td>\n",
       "      <td>-41</td>\n",
       "      <td>20</td>\n",
       "      <td>21.5</td>\n",
       "      <td>21.5</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>690</td>\n",
       "      <td>0.0</td>\n",
       "      <td>93.200000000000003</td>\n",
       "      <td>0.0</td>\n",
       "      <td>93.200000000000003</td>\n",
       "      <td>1606</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>2018</td>\n",
       "      <td>11</td>\n",
       "      <td>15</td>\n",
       "      <td>10</td>\n",
       "      <td>58</td>\n",
       "      <td>53</td>\n",
       "      <td>1</td>\n",
       "      <td>4000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>26.0</td>\n",
       "      <td>-51</td>\n",
       "      <td>-51</td>\n",
       "      <td>-1012.0</td>\n",
       "      <td>-41</td>\n",
       "      <td>20</td>\n",
       "      <td>21.5</td>\n",
       "      <td>21.5</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>690</td>\n",
       "      <td>0.0</td>\n",
       "      <td>93.200000000000003</td>\n",
       "      <td>0.0</td>\n",
       "      <td>93.200000000000003</td>\n",
       "      <td>1606</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   IMEI  Year  Month  Day  Hour  Minute  Seconds  tp      sp  EVVSP  \\\n",
       "0     7  2018     11   15    10      58       49   1     0.0    0.0   \n",
       "1     7  2018     11   15    10      58       50   1  1000.0    0.0   \n",
       "2     7  2018     11   15    10      58       51   1  2000.0    0.0   \n",
       "3     7  2018     11   15    10      58       52   1  3000.0    0.0   \n",
       "4     7  2018     11   15    10      58       53   1  4000.0    0.0   \n",
       "\n",
       "   EVVSP_delta  EVVSP_change  EVGPO  EVOAS  EVIGM_Latest  EVCOM_Latest  \\\n",
       "0          0.0           0.0      0   26.0           -51           -51   \n",
       "1          0.0           0.0      0   26.0           -51           -51   \n",
       "2          0.0           0.0      0   26.0           -51           -51   \n",
       "3          0.0           0.0      0   26.0           -51           -51   \n",
       "4          0.0           0.0      0   26.0           -51           -51   \n",
       "\n",
       "   EVACO_Z  EVIRT_Min  EVDI2  EVBMI_Latest  EVBMA_Latest  EVVAC  EVVAC_delta  \\\n",
       "0  -1008.0        -41     20          21.5          21.5    0.0          0.0   \n",
       "1  -1004.0        -41     20          21.5          21.5    0.0          0.0   \n",
       "2  -1016.0        -41     20          21.5          21.5    0.0          0.0   \n",
       "3  -1002.0        -41     20          21.5          21.5    0.0          0.0   \n",
       "4  -1012.0        -41     20          21.5          21.5    0.0          0.0   \n",
       "\n",
       "   EVVAC_change  EVODO  EVODOH          EVSMA_EWMA  EVSMA_delta  \\\n",
       "0           0.0    690     0.0  93.200000000000003          0.0   \n",
       "1           0.0    690     0.0  93.200000000000003          0.0   \n",
       "2           0.0    690     0.0  93.200000000000003          0.0   \n",
       "3           0.0    690     0.0  93.200000000000003          0.0   \n",
       "4           0.0    690     0.0  93.200000000000003          0.0   \n",
       "\n",
       "             EVSMA_in  combine  \n",
       "0  93.200000000000003     1606  \n",
       "1  93.200000000000003     1606  \n",
       "2  93.200000000000003     1606  \n",
       "3  93.200000000000003     1606  \n",
       "4  93.200000000000003     1606  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mybucket = storage.Bucket(BUCKET_NAME)\n",
    "data_csv = mybucket.object(FOLDER_NAME + \"/\" + TESTFILE)\n",
    "\n",
    "uri = data_csv.uri\n",
    "%gcs read --object $uri --variable data\n",
    "\n",
    "testset = pd.read_csv(BytesIO(data))\n",
    "testset.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import data_proces"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
